from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QTextEdit
import pandas as pd


class FormDialog(QDialog):
    """
    弹出表单对话框：用于列表详细内容
    """
    def __init__(self, data, width, height):
        """
        :param data: pandas 对象，格式为 lable名，控件类型, 控件文本, 是否可编辑
        """
        super().__init__()
        self.vbox = QVBoxLayout()
        self.data = data
        self.width = width
        self.height = height
        self.setWindowTitle("菜谱详情")
        self.init()

    def init(self):
        if self.data is None:
            return
        for row in self.data:
            hbox = QHBoxLayout()
            label = QLabel(row[0])
            label.setFixedWidth(60)
            if row[1] == 'QLineEdit':
                words = QLineEdit(row[2])
            elif row[1] == 'QTextEdit':
                words = QTextEdit(row[2])
            else:
                words = QLabel(row[2])
            words.setReadOnly(not row[3])

            hbox.addWidget(label)
            hbox.addWidget(words)
            self.vbox.addLayout(hbox)

        self.setLayout(self.vbox)
        self.setFixedSize(self.width, self.height)




